/*-----------------------------------------------------------------------------
	The contents of this file are subject to the Mozilla Public License
	Version 1.1 (the "License"); you may not use this file except in
	compliance with the License.You may obtain a copy of the License at
	http://www.mozilla.org/MPL/MPL-1.1.html
	
	Software distributed under the License is distributed on an "AS IS"
	basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
	License for the specific language governing rights and limitations
	under the License.
	
	The Original Code is Fever Framework code.
	
	The Initial Developer of the Original Code is Romain Ecarnot.
	Portions created by Initial Developer are Copyright (C) 2006
	the Initial Developer. All Rights Reserved.
	
	Contributor(s):
	
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
-----------------------------------------------------------------------------*/

import org.aswing.resizer.DefaultResizer;
import org.aswing.resizer.ResizeStrategy;
import org.aswing.resizer.ResizeStrategyImp;

import com.bourre.core.HashCodeFactory;
import com.bourre.utils.ClassUtils;

/**
 * Apply resizing strategy to <strong>AsWing components</strong>  
 * 
 * <p>Example
 * {@code
 *   var p : JPanel = new JPanel();
 *   p.setSize( 200, 100 );
 *   p.setLocation(20,20);
 *   p.setOpaque(true);
 *   p.setBackground( ASColor.DARK_GRAY );
 *   
 *   var c : ResizerController = ResizerController.init( p );
 *   c.setResizer( FvResizerFactory.create( new FvResizeEngine() ) );
 *   
 *   var pane : Container = FvAsWing.getInstance().getContainer();
 *   pane.setLayout( new EmptyLayout() );
 *   pane.append( p );
 * }
 * 
 * @see fvaswing.resizer.FvResizeEngine
 * 
 * @author Romain Ecarnot
 */
class fvaswing.resizer.FvResizerFactory extends DefaultResizer
{
	//-------------------------------------------------------------------------
	// Private properties
	//-------------------------------------------------------------------------
	
	private var _strategy : String;
	
	
	//-------------------------------------------------------------------------
	// Public API
	//-------------------------------------------------------------------------
	
	/**
	 * Constructs a real strategy to resize components.<br />
	 * Returns the {@link FvResizerFactory} created instance.
	 * 
	 * <p>If no strategy is defined, uses the default 
	 * <strong>org.aswing.resizer.ResizeStrategyImp</strong> one.
	 * 
	 * @param o Real strategy to use for component resizing
	 */
	public static function create( o : ResizeStrategy ) : FvResizerFactory
	{
		return new FvResizerFactory( o );	
	}
	
	
	//-------------------------------------------------------------------------
	// Private implementation
	//-------------------------------------------------------------------------
	
	/**
	 * Constructor.
	 * 
	 * <p>If no strategy is defined, uses the default 
	 * <strong>org.aswing.resizer.ResizeStrategyImp</strong>.
	 * 
	 * @param o Real strategy to use for component resizing
	 */
	private function FvResizerFactory( o : ResizeStrategy )
	{
		super();
		
		_strategy = ( o ) 
				? ClassUtils.getFullyQualifiedClassName( o )
				: ClassUtils.getFullyQualifiedClassName( new ResizeStrategyImp() );
	}	
	
	/**
	 * Creates and returns a real resizing strategy
	 * 
	 * @param wSign Horizontal resizing direction	 * @param hSign Vertical resizing direction
	 */
	private function createResizeStrategy( wSign : Number, hSign : Number ) : ResizeStrategy
	{
		return HashCodeFactory.buildInstance( _strategy, arguments ); 
	}	
}